package com.wyd.rule;

import com.wyd.entity.Context;
import com.wyd.entity.DseProductPriorityInfo;
import com.wyd.enums.WeightEnum;
import com.wyd.utils.ScoreUtils;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.annotation.Rule;

@Rule(name = "product_mtk_rule", description = "产品mtk", priority = 2)
@Slf4j
public class ProductMtkRule {

  @Condition
  public boolean when(@Fact("ct") Context ct) {
    //判断配置的规则是否包括mtk项
    return ct.getWeightTypeRuleMap().containsKey(WeightEnum.MTK.getType());
  }

  @Action
  public void action(@Fact("ct") Context ct) {
    for(DseProductPriorityInfo product : ct.getDseProductList()){
        if(product.getPlmnStrength() <= ct.getPlmnStrength()){ //信号级别小于配置值代表更优先
            int score = product.getScore();
            int weight = ct.getWeightTypeRuleMap().get(WeightEnum.MTK.getType());
            int pScore = ScoreUtils.getScore(WeightEnum.MTK,product.getAvailability());
            product.setScore(score + weight + pScore); //数字越小，分数越高
            log.info("{}-MTK符合条件，增加加权值:{},mtk分数：{}，最后分数：{}", product.getDseProductId(),weight,pScore,product.getScore());
        }
    }

  }
}
